<?php

function get_protocal($param) {
	return ( $param & 0xFFFF );
}
function get_login_type($param) {
	return ( $param >> 16 );
}
$connect = mysql_connect('localhost','root','lxygwqfqsgctys');
//$connect = mysql_connect('localhost','test','123456');
if (! $connect)
{
	die('Could not connect: ' . mysql_error());
}

mysql_select_db('reward', $connect);
// some code
$result = null;
$result->return_code = 0;
$result->protocal =get_protocal( $_GET['protocal'] );
$key = $_GET['key'];

$sql = "SELECT * FROM reward WHERE reward_key = '$key' ";
$query = mysql_query($sql, $connect);
if (mysql_num_rows($query) >= 1) {
	$row = mysql_fetch_object($query);
	if ($row->flag == 1) {
		$result->return_code = 20001;
	}
	else {
		$result->coin = $row->coin;
		$result->diamond = $row->diamond;
		$sql = "UPDATE reward SET flag = 1 WHERE rewardid = $row->rewardid ";
		$query = mysql_query($sql, $connect);
		if (mysql_affected_rows($connect) == 0) {
			$result->return_code = 1;
		}
	}
}
else {
	$result->return_code = 20002;
}
echo (json_encode($result));

mysql_close($connect);
